package ogon.grid;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;

public class OgonGridBase extends Activity implements AdapterView.OnItemSelectedListener{
    /** Called when the activity is first created. */
	TextView selection;
	String[] items = {"prueba","suca","bene","brava","giu","davanti"};
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        selection=(TextView)findViewById(R.id.selection);
        GridView g = (GridView)findViewById(R.id.gridOgon);
        g.setAdapter(new MyPersonalAdapter(this, android.R.layout.simple_list_item_1,items));
        g.setOnItemSelectedListener(this);
    }
    public void onItemSelected(AdapterView<?> parent, View v, int position, long id){
    	selection.setText(items[position]);
    }
    private class MyPersonalAdapter extends ArrayAdapter{
    	Context ctxt;
    	public MyPersonalAdapter(Context ctxt,int resource, String[] items) {
			super(ctxt, resource,items);
			this.ctxt = ctxt;
		}
    	public View getView(int position, View convertView, ViewGroup parent){
    		TextView label = (TextView)convertView;
    		if(convertView == null){
    			convertView=new TextView(ctxt);
    			label=(TextView)convertView;
    		}
    		label.setText(items[position]);
    		return convertView;
    	}
    }
	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		selection.setText("");		
	}
}